// pages/content/content.js
const app=getApp();
let isSend=false;
Page({
    
    /**
     * 页面的初始数据
     */
    data: {
        msgList: [],
        concertList:[],
        singerList:[],
        Buffer:null,
        searchcontent:'',//输入的值
        searchList:[],
        shop_tab_flag:false,
        block:false,
        block1:false,
        hotList:[],
        selectList:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

        let that=this;
        wx.request({
            
            url:'http://49.233.35.127/admin/singer',
            success:function(res){
                const data = res.data
                const datalist=app.globalData.datalist
                for(let i=0;i<data.length;i++){
                    if(data[i].IsHot==1){
                        app.globalData.datalist.push(data[i])
                    }
                    that.setData({
                        singerList:datalist,
                        hotList:datalist.slice(0,5)
                    })
                }
                
            }
        })
        wx.request({
          url: 'http://49.233.35.127/admin/album',
          success:function (res) {

              const data=res.data
              that.setData({
                  msgList:data
              })
          }
        })
        function rTime(date) {
            var json_date = new Date(date).toJSON();
            return new Date(new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '') 
        }


        wx.request({
            url:'http://49.233.35.127/admin/vocal/',
            success:function(res){
                const data = res.data
                
                let dlist = []
                for(let i=0;i<data.length;i++){
                    if(data[i].isHot==1){
                        dlist.push(data[i])
                    }
                }
                for(let i=0;i<dlist.length;i++){
                    dlist[i].time=(rTime(dlist[i].time).split(' '))[0]    
                    that.setData({
                        concertList:dlist
                    })
                }    
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },
    getAblum:function(e){
        
        for(let i=0;i<this.data.msgList.length;i++){ 
            
            if(e.target.id==i){
                const data=this.data.msgList[i].name

                wx.navigateTo({
                   url: '/pages/content/ablum?data='+data,
                })
            }
        }
        
    },
    discover:function(){
        app.globalData.i++
        if(app.globalData.i%2 !== 0){
            this.setData({
                shop_tab_flag:true,
                block:true,
                block1:false
            })
        }else{
            this.setData({
                shop_tab_flag:false,
                block:false,
                block1:false
            })
        }

        
    },
    //模糊查询
    KeyInput:function (event) {

        this.setData({
           searchcontent: event.detail.value.trim(),
           block:false,
           block1:true
        })
        if(isSend){
            return
        }
        isSend=true
        // if(this.data.searchcontent){
            let that=this
            setTimeout(()=>{
                //发请求
                let arr=[]
                wx.request({
                    url: 'http://49.233.35.127/Wx/searchSinger/?name='+this.data.searchcontent,
                    success:function (res) {
                        let List = []
                        if(res.data[0]){
                            List.push(res.data[0])
                            if(res.data[1]){
                                List.push(res.data[1])
                                if(res.data[2]){
                                    List.push(res.data[2])
                                    if(res.data[3]){
                                        List.push(res.data[3])
                                    }
                                }
                            }
                        }
                        that.setData({
                            selectList:List
                        })
                        
                        
                    }
                })
                isSend=false
            },500)
        // }
    },
    choice1:function(e){
        for(let i=0;i<this.data.selectList.length;i++){
            if(e.target.id==i){
                const data=this.data.selectList[i].Name
                wx.navigateTo({
                    url:"/pages/content/alonesinger?key="+ data
                }) 
            }
        }
    },
    choice:function(e) {
        

        for(let i=0;i<5;i++){
            if(e.target.id==i){
                
                
                const data= this.data.hotList[i].Name
                wx.navigateTo({
                    url:"/pages/content/alonesinger?key="+ data
                }) 
            }

        }

    },
    getSinger:function(e){

        var index = e.currentTarget.dataset.index;
        for(let i=0;i<7;i++){
            if(index==i){
                
                const data=app.globalData.datalist[i].Name
                wx.navigateTo({
                    url:"/pages/content/alonesinger?key="+data
                })
            }
            
            
            
        }
        
        

    },

    getMore:function(){
        wx.navigateTo({
            url:"/pages/content/singer"
        })
    },
    getConcert:function(e){
        for(let i=0;i<4;i++){
            if(e.target.id==i){
                const data=this.data.concertList[i].name
                const singer=this.data.concertList[i].singer
                wx.navigateTo({
                    url:'/pages/content/concert?data='+data+'&key='+singer
                })
                

            }
            
        }
        


    },
    getMoreConcert:function(){
        wx.navigateTo({
            url:"/pages/content/moreconcert"
        })
    },


    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})